import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'
// import Home from '../views/Home.vue'
// import Test1 from '../views/Test1.vue'
// import Test2 from '../views/Test2.vue'


// const originalPush = VueRouter.prototype.push
// VueRouter.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
//   return originalPush.call(this, location).catch(err => err)
// }

Vue.use(VueRouter)
// //获取原型对象上的push函数
// const originalPush = VueRouter.prototype.push
// //修改原型对象中的push方法
// VueRouter.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};


const routes = [{
    path: '/',
    name: 'Login',
    component: Login,
    hidden: true
  },
  // {
  //   path: '/home',
  //   name: '导航一',
  //   component: Home,
  //   // 让下面的路由在home组件内进行跳转，如果和home同一级会整个页面跳转
  //   children: [{
  //       path: '/test1',
  //       name: '选项一',
  //       component: Test1
  //     },
  //     {
  //       path: '/test2',
  //       name: '选项二',
  //       component: Test2
  //     },
  //   ]
  // },

]

const router = new VueRouter({
  routes
})

export default router